package com.yuzhi.master.drainMsgTemplate.controller;

import java.util.List;
import java.util.Arrays;

import com.yuzhi.common.core.controller.BaseController;
import com.yuzhi.common.core.domain.entity.SysDictData;
import com.yuzhi.common.core.page.PageDataInfo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.yuzhi.common.core.domain.ApiResult;
import com.yuzhi.master.drainMsgTemplate.domain.vo.DrainMsgTemplateVo;
import com.yuzhi.master.drainMsgTemplate.domain.bo.DrainMsgTemplateBo;
import com.yuzhi.master.drainMsgTemplate.domain.request.DrainMsgTemplateReq;
import com.yuzhi.master.drainMsgTemplate.service.IDrainMsgTemplateService;
import com.yuzhi.common.util.poi.ExcelUtil;

/**
 * 消息通知模板
 *
 * @author coding123
 * @date 2025-08-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/drainMsgTemplate")
public class DrainMsgTemplateController extends BaseController {

    private final IDrainMsgTemplateService idrainMsgTemplateService;

    /**
     * 查询消息通知模板列表
     */
    @SaCheckPermission("system:drainMsgTemplate:list")
    @PostMapping("/list")
    public ApiResult<PageDataInfo> list(@RequestBody DrainMsgTemplateReq request) {
        return ApiResult.ok(idrainMsgTemplateService.queryPageList(request));
    }

    /**
     * 导出消息通知模板列表
     */
    @SaCheckPermission("system:drainMsgTemplate:export")
    @PostMapping("/export")
    public void export(DrainMsgTemplateReq request, HttpServletResponse response) {
        List<DrainMsgTemplateVo> list = idrainMsgTemplateService.queryList(request);
        ExcelUtil.exportExcel(list, "消息通知模板", DrainMsgTemplateVo.class, response);
    }

    /**
     * 获取消息通知模板详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:drainMsgTemplate:query")
    @GetMapping("/getInfoById/{id}")
    public ApiResult<DrainMsgTemplateVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return ApiResult.ok(idrainMsgTemplateService.queryById(id));
    }

    /**
     * 新增消息通知模板
     */
    @SaCheckPermission("system:drainMsgTemplate:add")
    @PostMapping("/add")
    public ApiResult<Void> add(@Validated @RequestBody DrainMsgTemplateBo bo) {
        return toAjax(idrainMsgTemplateService.insertByBo(bo));
    }

    /**
     * 修改消息通知模板
     */
    @SaCheckPermission("system:drainMsgTemplate:edit")
    @PostMapping("/edit")
    public ApiResult<Void> edit(@Validated @RequestBody DrainMsgTemplateBo bo) {
        return toAjax(idrainMsgTemplateService.updateByBo(bo));
    }

    /**
     * 删除消息通知模板
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:drainMsgTemplate:remove")
    @DeleteMapping("/removeBatchById/{ids}")
    public ApiResult<Void> removeBatchById(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(idrainMsgTemplateService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 删除消息通知模板
     *
     * @param id 主键
     */
    @SaCheckPermission("system:drainMsgTemplate:remove")
    @DeleteMapping("/removeById/{id}")
    public ApiResult<Void> removeById(@NotEmpty(message = "主键不能为空")
                                  @PathVariable String id) {
        return toAjax(idrainMsgTemplateService.deleteById(id, true));
    }

    /**
     * 消息通知模板变量
     * @return
     */
    @GetMapping("/selectTemplateDict")
    public ApiResult<List<SysDictData>> selectTemplateDict( ) {

        List<SysDictData>  dictDataList  =  idrainMsgTemplateService.selectTemplateDict();

        return ApiResult.ok(dictDataList);
    }


}
